<#include "../common/header.htm">
<body class="gray-bg top-navigation" style="background-color: #fff;">
<div class="content-wrapper">
	<section class="content">
		<div class="row">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs navzi">
                        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">一键导入</a>
                        </li>
                        <li class="">
                        	<a data-toggle="tab" href="#tab-2" aria-expanded="false">自定义导入</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active">
	                    	<div class="importti">
								<span class="importstar">*</span>
								<span class="importfont">"温馨提示：每次选择导入的文件不要超过10个，主要支持的文件格式有：.xls，.xlsx，.csv，.pdf，.txt"</span>
							</div>
                            <div class="panel-body">
                                <div class="box">
									<form action="#" method="get" id="listForm" >
										<div class="form-group">
											<input id="file-1" accept=".pdf,.csv, .xls, .xlsx,.txt" type="file" name="fileUpload" multiple="multiple" class="file" data-overwrite-initial="false" />
											<input type="hidden" id="nextNumber" name="nextNumber" value="${nextNumber!}"/>
											<input type="hidden" id="callbackResult" name="callbackResult"/>
										</div>
									</form>
								</div>
                            	<!--上传按钮 bengin-->
								<div class="importAndClear">
									<button onclick="beginImport()"  type="button" class="btn btn-primary up">
										开始导入
									</button>
									<!--<a href="#" style="display: none;" onclick="clearFile()">清空</a>-->
								</div>
							</div>
							<button onclick="showCaseObjectMapping()" type="button" id="caseObjectBill" style="display: none;" class="gldx el-button el-button--primary">
								关联案件对象<span class="gldxwen" data-container="body" data-toggle="popover" data-placement="top"
											data-content="<li>1,一键导入主要针对在模板库存中存在的账单</li><li>2,自定义导入主要针对格式化比较复杂的账单，导入完成后需手动配置账单标题</li>">></span>
							</button>
							<!-- end -->
							<!--导入结果-->
							<div class="result">
								<el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
									<el-tab-pane label="导入结果" name="first">
										<table id="dg"></table>
									</el-tab-pane>
									<el-tab-pane label="已导入数据" name="second">
										<el-select v-model="excelVal" placeholder="请选择" @change="changeHandle">
											<el-option
													v-for="item in logDataArr"
													:key="item.DEAL_FLOW_UUID"
													:label="item.FILE_NAME"
													:value="item.DEAL_FLOW_UUID">
											</el-option>
										</el-select>
										<div class="detail">
											<table id="dg2"></table>
										</div>
									</el-tab-pane>
								</el-tabs>
							</div>
                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                                <form action="#" method="get" >
									<div class="form-group">
										<input id="file-2" accept=".pdf,.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,.txt" type="file" name="fileUpload" multiple="multiple" class="file" data-overwrite-initial="false" />
									</div>
								</form>
								<div class="importAndClearZdy">
									<button onclick="beginMapping()" id="beginMapping" style="margin-left: 106px;" type="button" class="btn btn-primary be">
										开始解析
									</button>
									<button onclick="zdyClearFile()" id="clearFile" style="display: none;" type="button" class="btn btn-primary zdyclear">
										清空
									</button>
									<button onclick="importZdy()" id="importZdy" type="button" style="display: none;" class="btn btn-primary ex">
										导入
									</button>
									<button onclick="initTitlePoll()" type="button" class="btn btn-primary ex">
										标题管理
									</button>
								</div>
							</div>
							<div class="zdyresult">
								<table id="zdydg"></table>
							</div>
							<div class="zdyresultend">
								<!--导入结果-->
								<el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
									<el-tab-pane label="导入结果" name="first">
										<table id="dgzdy"></table>
									</el-tab-pane>
									<el-tab-pane label="已导入数据" name="second">
										<el-select v-model="excelVal" placeholder="请选择" @change="changeHandle">
											<el-option
													v-for="item in logDataArr"
													:key="item.DEAL_FLOW_UUID"
													:label="item.FILE_NAME"
													:value="item.DEAL_FLOW_UUID">
											</el-option>
										</el-select>
										<div class="detail">
											<table id="dg2zdy"></table>
										</div>
									</el-tab-pane>
								</el-tabs>
	                        </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
	</section>
</div>
<script type="text/javascript">
	 /** 回去传值 **/
 	 var dialog = top.dialog.get(window);
 	 var case_uuId = dialog.data; // 获取对话框传递过来的数据
 	 /*导入成功文件id*/
   	 var fileUUids = new Array();
 	 $(function(){
	 	 $.ajax({
	        type : "GET",
	        url : "${ctx}/casemanage/setCaseUuid?caseUuid="+case_uuId,
	        success: function(data){
	        }
	    });
 	 });
	/*初始化fileinput插件*/
	var obj=$("#file-1").fileinput({
		language: 'zh',//汉化
		uploadUrl : '${ctx}/bill/xx?uid='+case_uuId,//上传地址
		allowedFileExtensions : ['txt' ,'csv', 'xls' , 'xlsx','pdf'],//支持格式
		showClose : false,//屏蔽x号关闭案件
		uploadAsync:false,//采用同步上传
		showUploadedThumbs : false,//是否在预览窗口中持续显示上传的文件缩略图
		overwriteInitial : false,//将其设置为false将有助于始终从数据库中显示已保存的图像或文件
		browseOnZoneClick : true,//浏览区域点击
		autoReplace : true,//是否自动替换当前文件，设置为true时，再次选择文件， 会将当前的文件替换掉。
		maxFileSize : 0,
		maxFilesNum : 0,
		maxFileCount:10,
		showBrowse:true,
		showUpload: true,//Boolean 是否显示上传按钮 true,
		showRemove : true,//关闭删除按钮
		removeFromPreviewOnError : true,
		layoutTemplates :{
			actionUpload : '',
			actionZoom : ''   //去除上传预览缩略图中的查看详情预览的缩略图标。
		},
		previewSettings: {
			image: {width: "100px", height: "100px"},
		},
		initialPreviewAsData: true,
		allowedPreviewTypes :null, //设置为空，null或false以禁用所有类型的预览
		showPreview :true, //是否显示预览
		preferIconicPreview: true, // 开启用图标替换预览效果
		previewFileIconSettings: {
			'docx': '<i class="fa fa-file-word-o text-primary"></i>',
			'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
			'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
			'doc': '<i class="fa fa-file-word-o text-primary"></i>',
			'xls': '<i class="fa fa-file-excel-o text-success"></i>',
			'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
			'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
			'txt': '<i class="fa fa-file-text-o text-info"></i>',
		},
		slugCallback : function(filename) {
			return filename.replace('(', '_').replace(']', '_');
		}
	}).on('filepreupload', function(event, data, previewId, index) {     //上传中
		var form = data.form, files = data.files,filenames = data.filename, extra = data.extra,
				response = data.response, reader = data.reader;
	}).on("filebatchuploadsuccess", function(event, data) {    //文件上传成功
		fileUUids = new Array();
		$('.result').show();
        $('#caseObjectBill').show();
		$(".importAndClear button").html("开始导入")
		$(".importAndClear button").attr('disabled',false);
		$(".importAndClear a").show();
        console.log(data.response.result)
        if(data.response.result =='fail'){
        	toastr.error(data.response.data);
        }else{
	        var ids=data.response.data.ids;
	        if (ids){
	            dg(ids)
	        }
        }
		$(".fileinput-remove-button").click();
	}).on('fileerror', function(event, data, msg) {
	}).on('upload', function(event, data, msg) {
	}).on("filesuccessremove", function(event, data) {
		//检查当前文件的个数，如果等于0的话就清空当前页面
		if ($(".file-preview-frame").length==1) {
			clearFile();
		}
	}).on("fileuploaded", function(event, data, previewId, index) {
	}).on("filecleared",function (event, data, msg) { //文件被全部删除
		console.log("文件被全部删除")
	}).on("fileclear",function (event, data, msg) { //某个文件被删除
		console.log("某个文件被删除")
	}).on("upload",function (event, data, msg) {
	}).on("filebatchselected",function (event, files) {//文件被上传
        if (files.length>0){
            for (let i = 0; i < files.length; i++) {
                let filename=files[i].name;
                changFilePng(filename,i)
            }
            $(".importAndClear a").show()
        }else{
            $(".importAndClear a").hide()
        }
	});
	/*列显示下拉框*/
    var cmenu;
	/* 未匹配上的标题 */
	var tempTitle;
	/* 匹配上的标题 */
	var mappingTitle;
	/* 选中要匹配的标题行 */
	var selectRowIndex;
	/*文件名称*/
	var fileName;
	/*文件大小*/
	var fileSize;
	/* 文件唯一标识符 */
	var fileUuid;
	function importZdy(){
		var datagridTitle = new Array();
        var fields = $("#zdydg").datagrid('getColumnFields');
        for (var i = 0; i < fields.length; i++) {
            var option = $("#zdydg").datagrid('getColumnOption', fields[i]);
            if (option.field != "checkItem" && option.hidden != true) { //过滤勾选框和隐藏列
                datagridTitle.push(option.title);
            }
        }
        debugger
		var data = {"mappingTitle" : mappingTitle,"selectRowIndex": selectRowIndex,"fileUuid": fileUuid,"fileName": fileName,"fileSize": fileSize,caseId:case_uuId};
        var showInputFlat = false;
        for (var i = 0; i < datagridTitle.length; i++) {
			if(datagridTitle[i].indexOf("未知") >= 0){
				showInputFlat = true;
				break;
			}
        }
		if(showInputFlat){
			var d = top.dialog({
	            title: '提示',
	            content: '标题未匹配完整，您是否要继续导入?',
	            okValue: '确 定',
	            ok: function() {
	            	$.ajax({
	                	type : "post",
	                    url : "${ctx}/bill/zdyImport",
	                    contentType : "application/json;charset=UTF-8",
	                    data : JSON.stringify(data),
	                    success : function (data) {
	                    	if(data.errorMsg){
	                    		toastr.error(data.errorMsg);
	                    		return;
	                    	}
	                		if (data.ids){
	        	        		$(".zdyresult").hide();
	        	        		$("#importZdy").attr("style","display:none;");
	        	        		$("#beginMapping").html("开始解析")
	        	        		$("#beginMapping").attr("disabled",false);
	        	        		$("#clearFile").attr("style","display:none;");
	        	        		$(".fileinput-remove-button").click();
	        	        		$(".zdyresultend").show();
	                			dgzdy(data.ids)
	                		}
	                    }
	                });
	                return false;
	            },
	            cancelValue: '取消',
	            cancel: function() {}
	        });
	        d.showModal();
		}else{
			$.ajax({
	        	type : "post",
	            url : "${ctx}/bill/zdyImport",
	            contentType : "application/json;charset=UTF-8",
	            data : JSON.stringify(data),
	            success : function (data) {
	            	debugger
	            	if(data.errorMsg){
	            		toastr.error(data.errorMsg);
	            		return;
	            	}
	        		if (data.ids){
		        		$(".zdyresult").hide();
		        		$("#importZdy").attr("style","display:none;");
		        		$("#beginMapping").html("开始解析")
		        		$("#beginMapping").attr("disabled",false);
		        		$("#clearFile").attr("style","display:none;");
		        		$(".fileinput-remove-button").click();
		        		$(".zdyresultend").show();
	        			dgzdy(data.ids)
	        		}
	            }
	        });
		}
	};
	/* 初始化fileinput插件 */
	var obj=$("#file-2").fileinput({
		language: 'zh',//汉化
		uploadUrl : '${ctx}/bill/billImportMapping?uid='+case_uuId,//上传地址
		allowedFileExtensions : ['txt' ,'csv', 'xls' , 'xlsx','pdf'],//支持格式
		showClose : false,//屏蔽x号关闭案件
		uploadAsync : false,//采用同步上传
		showUploadedThumbs : false,//是否在预览窗口中持续显示上传的文件缩略图
		overwriteInitial : false,//将其设置为false将有助于始终从数据库中显示已保存的图像或文件
		browseOnZoneClick : true,//浏览区域点击
		autoReplace : true,//是否自动替换当前文件，设置为true时，再次选择文件， 会将当前的文件替换掉。
		maxFileSize : 0,
		maxFilesNum : 0,
		maxFileCount : 1,
		showBrowse : true,
		showUpload : true,//Boolean 是否显示上传按钮 true,
		showRemove : true,//关闭删除按钮
		removeFromPreviewOnError : true,
		layoutTemplates : {
			actionUpload : '',
			actionZoom : ''   //去除上传预览缩略图中的查看详情预览的缩略图标。
		},
		previewSettings: {
			image: {width: "100px", height: "100px"},
		},
		initialPreviewAsData : true,
		allowedPreviewTypes : null, //设置为空，null或false以禁用所有类型的预览
		showPreview : true, //是否显示预览
		preferIconicPreview : true, // 开启用图标替换预览效果
		previewFileIconSettings : {
			'docx': '<i class="fa fa-file-word-o text-primary"></i>',
			'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
			'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
			'doc': '<i class="fa fa-file-word-o text-primary"></i>',
			'xls': '<i class="fa fa-file-excel-o text-success"></i>',
			'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
			'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
			'txt': '<i class="fa fa-file-text-o text-info"></i>',
		},
		slugCallback : function(filename) {
			return filename.replace('(', '_').replace(']', '_');
		}
	}).on('filepreupload', function(event, data, previewId, index) {     //上传中
		var form = data.form, files = data.files,filenames = data.filename, extra = data.extra,
				response = data.response, reader = data.reader;
	}).on('filebatchuploaderror', function(event, data, msg) {
		$('.zdyresult').hide();
		$("#importZdy").attr("style","display:none;");
		$("#clearFile").attr("style","display:none;");
		$("#beginMapping").html("开始解析")
		$("#beginMapping").attr("disabled",false);
		$(".fileinput-remove-button").click();
		toastr.error(data.response.data);
	}).on("filebatchuploadsuccess", function(event, data) {   //文件上传成功
        if(data.response.result =='fail'){
        	$('.zdyresult').hide();
    		$("#importZdy").attr("style","display:none;");
    		$("#clearFile").attr("style","display:none;");
    		$("#beginMapping").html("开始解析")
    		$("#beginMapping").attr("disabled",false);
    		$(".fileinput-remove-button").click();
        	toastr.error(data.response.data);
        }else{
			fileUuid = data.response.data[0].fileUuid;
			fileName = data.files[0].name;
			fileSize = data.files[0].size;
			$('.zdyresult').show();
			$("#beginMapping").attr("disabled",true);
			var collll = new Array();
	    	$.ajax({
		        url:"${ctx}/bill/findTempColumnSize",
		        type : "get",
		        dataType :'json',
		        data:{caseId:case_uuId},
		        success : function (obj) {
		        	for (i = 0; i < Number(obj) -1; i++) { 
		        		var index = i + 1;
	                    var str = {"field": "TEMP_"+index,"align": "center","title": "未知"+index};
	                    collll.push(str);
	        	    }
		        	collll = [collll];
		        	$('#zdydg').datagrid({
		    			url:"${ctx}/bill/findDealFlowTemp4Page?caseId="+case_uuId,//请求数据url
		    			columns: collll,
		    			height:($(window).height())-($('.panel-body').height())-400,
		    			method: 'post',
		    			iconCls: 'icon-save',
		    			width:1500,
		    			pageList:[20,40,50,100],//每页记录数选择范围设置
		    			pageNumber:1,//当前页号,
		    			pageSize:20,//每页显示记录数
		    			loadMsg:"正在加载，请稍后",//加载数据时的提示信息
		    			emptyMsg:"暂无信息",//加载数据为空时的信息
		    			rownumbers:true,//序号
		    			fitColumns: true,//使表格自适应页面宽度
		    			pagination: true,//是否分页
		    			singleSelect: true,
		                onClickRow: function(rowIndex, rowData){//选中标题行
		                	$("#zdydg").datagrid("loading");
		                	$.ajax({
		            			url: "${ctx}/bill/TempTitleMapping",
		            			data: rowData,
		            			success: function (data) {
		            				var str = '';
		            				$.each(data.mappingTitle ,function (i,n) {
		            					var newStr=i.substring(i.lastIndexOf('_'),i.length); 
		            					var option = $('#zdydg').datagrid("getColumnOption", "TEMP"+newStr)
		            					option.title = n;
			                		});
		            				$('#zdydg').datagrid();
		            				mappingTitle = data.mappingTitle;
		            				tempTitle = data.notInTitle;
		            				selectRowIndex = rowIndex;
		                        }
		            		});
		                },
		                onLoadSuccess:function(){//修改未匹配上的标题颜色
		                	// 更改表头颜色
		                	var trArr = $(this).prev().find("tr.datagrid-header-row");
		                	var trObj = trArr[0];
		                	var tdArr = trObj.cells;
		                	for (var i = 0; i < tdArr.length; i++) {
		                		if(tdArr[i].innerText.indexOf("未知") >= 0) { 
		                			tdArr[i].style.backgroundColor = "red";
		                			$("#importZdy").attr("style","display:none;");
		                		}
		                	}
		                	/* if(trObj.innerText.indexOf("未知") < 0){
		                		$("#importZdy").attr("style","display:initial;");
		                	} */
		                	$("#importZdy").attr("style","display:initial;");
		                	$("#zdydg").datagrid("loaded");
	                	},
		                onHeaderContextMenu: function(e, field){//设置标题右键菜单
		                    e.preventDefault();
		                    cmenu = $('<div/>').appendTo('body');
		                    cmenu.menu({
		                    	onClick: function(item){
		                    		//获取点击的字段对象
		                    		var option = $('#zdydg').datagrid("getColumnOption", field)
		                    		//设置标题名称
	            					option.title = item.name;
		                    		$('#zdydg').datagrid();
		                    		//删除选择后的标题
		                    		removeByValue(tempTitle,item.name);
		                    		//更新匹配上的标题
		                    		mappingTitle[field] = item.name;
		                        }
		                    });
		                    if(tempTitle != null){
		                    	for(var i = 0; i < tempTitle.length; i++){
		                            var f = tempTitle[i];
		                            cmenu.menu('appendItem', {
		                                text: f,
		                                name: f
		                            });
		                        }
		                    }
		                    cmenu.menu('show', {
		                        left:e.pageX,
		                        top:e.pageY
		                    });
		                }
		    		});
		        }
		    });
        }
	}).on("filebatchselected",function (event, files) {//文件被上传
		if (files.length>0){
			$("#clearFile").show()
		}else{
			$("#clearFile").hide()
		}
	});
	$(function () {
		$(".input-group.file-caption-main.no-browse").hide();
		$(".input-group.file-caption-main").hide();
	});
	function beginImport() {
		let fileLength=$(".file-preview-frame").length;
		if (!fileLength) {
			toastr.info("请选择文件");
			return;
		}
		$('.result').hide();
		$('#caseObjectBill').hide();
		$(".fileinput-upload-button").click();
		$(".importAndClear button").html("正在导入...");
		$(".importAndClear button").attr('disabled',true);
		$(".importAndClear a").hide();
		importLog.excelVal='';
		importLog.logDataArr=[];
		importLog.activeName='first';
	};
	function beginMapping() {
		let fileLength=$(".file-preview-frame").length;
		if (!fileLength) {
			toastr.info("请选择文件");
			return;
		}
		$(".fileinput-upload-button").click();
		$("#beginMapping").html("解析中...");
    	$("#beginMapping").attr("disabled",true);
		$('.zdyresult').hide();
		importLog2.excelVal=''
		importLog2.logDataArr=[]
		importLog2.activeName='first'
	};
	function clearFile() {
		$('.result').hide();
		$(".fileinput-remove-button").click();
	};
	function zdyClearFile() {
		$('.zdyresult').hide();
		$("#importZdy").attr("style","display:none;");
		$("#clearFile").attr("style","display:none;");
		$("#beginMapping").html("开始解析")
		$("#beginMapping").attr("disabled",false);
		$(".fileinput-remove-button").click();
	};
	function dg(ids){
		$('#dg').datagrid({
			url: '${ctx}/datalog/importDataList_easyui',
			method: 'post',
			iconCls: 'icon-save',
			queryParams:{//每次请求的参数
				ids: ids,
				caseId:case_uuId
			},
			pageList:[10,20,40,50,100],//每页记录数选择范围设置
			pageNumber:1,//当前页号,
			pageSize:10,//每页显示记录数
			loadMsg:"正在加载，请稍后",//加载数据时的提示信息
			emptyMsg:"暂无信息",//加载数据为空时的信息
			//height: 710,
			// width:1300,
			//width:1300,
			rownumbers:true,//序号
			fitColumns: true,//使表格自适应页面宽度
			pagination: true,//是否分页
			singleSelect: true,
			columns:[[ //每一列的具体设置。
				{field:'FILE_NAME',title:'文件名',width:'20%'},
				{field:'FILE_SIZE',title:'文件大小',width:'20%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if (value < 1024) {
				            return value + 'B';
				      	} else if (value < (1024*1024)) {
				            var temp = value / 1024;
				            temp = temp.toFixed(2);
				            return temp + 'KB';
				      	} else if (value < (1024*1024*1024)) {
				        	var temp = value / (1024*1024);
				            temp = temp.toFixed(2);
				         	return temp + 'MB';
				    	} else {
				         	var temp = value / (1024*1024*1024);
				         	temp = temp.toFixed(2);
				         	return temp + 'GB';
				      	}
						return value;
					}
				},
				{field:'IMPORT_RESULT',title:'导入结果',width:'20%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						value+="(导入"+row.SUCCESS_NUMBER+"条)"
						return value
					}
				},
				{field:'IMPORT_DESC',title:'失败原因',width:'20%'},
				{field:'IMPORTDETAILID',title:'操作',align:'center',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if(row.IMPORT_RESULT == '成功'){
                        	return "<a href='#' onclick='delLog(\""+row.DEAL_FLOW_UUID+"\",1,\""+row.IMPORTDETAILID+"\")'>删 除</a>"
                    	}else{
                    		return "-";
                    	}
					}
				}
			]],
			onLoadSuccess: function(data){
				if (!data.rows.length){
					$('.result').hide();
				}else{
					importLog.logDataArr=data.rows;
					//文件导入成功，将文件DEAL_FLOW_UUID保存fileUUids
                    $.each(data.rows ,function (i,n) {
                    	fileUUids.push(n.DEAL_FLOW_UUID);
            		});
				}
			}
		});
	};
	function dgzdy(ids){
		$('#dgzdy').datagrid({
			url: '${ctx}/datalog/importDataList_easyui',
			method: 'post',
			iconCls: 'icon-save',
			queryParams:{//每次请求的参数
				ids: ids,
				caseId:case_uuId
			},
			pageList:[10,20,40,50,100],//每页记录数选择范围设置
			pageNumber:1,//当前页号,
			pageSize:10,//每页显示记录数
			loadMsg:"正在加载，请稍后",//加载数据时的提示信息
			emptyMsg:"暂无信息",//加载数据为空时的信息
			//height: 710,
			width:1300,
			rownumbers:true,//序号
			fitColumns: true,//使表格自适应页面宽度
			pagination: true,//是否分页
			singleSelect: true,
			columns:[[ //每一列的具体设置。
				{field:'FILE_NAME',title:'文件名',width:'20%'},
				{field:'FILE_SIZE',title:'文件大小',width:'20%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if (value < 1024) {
				            return value + 'B';
				      	} else if (value < (1024*1024)) {
				            var temp = value / 1024;
				            temp = temp.toFixed(2);
				            return temp + 'KB';
				      	} else if (value < (1024*1024*1024)) {
				        	var temp = value / (1024*1024);
				            temp = temp.toFixed(2);
				         	return temp + 'MB';
				    	} else {
				         	var temp = value / (1024*1024*1024);
				         	temp = temp.toFixed(2);
				         	return temp + 'GB';
				      	}
						return value;
					}
				},
				{field:'IMPORT_RESULT',title:'导入结果',width:'20%',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						value+="(导入"+row.SUCCESS_NUMBER+"条)"
						return value
					}
				},
				{field:'IMPORT_DESC',title:'失败原因',width:'20%'},
				{field:'IMPORTDETAILID',title:'操作',align:'center',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if(row.IMPORT_RESULT == '成功'){
                        	return "<a href='#' onclick='delLog(\""+row.DEAL_FLOW_UUID+"\",1,\""+row.IMPORTDETAILID+"\")'>删 除</a>"
                    	}else{
                    		return "-";
                    	}
					}
				}
			]],
			onLoadSuccess: function(data){
				debugger
				if (!data.rows.length){
					$('.zdyresultend').hide()
				}else{
					importLog2.logDataArr=data.rows
				}
			}
		});
	};
	function dg2(excelLog){
		if (!case_uuId) {
			toastr.error("案件id为空");
			return;
		}
		if (!excelLog) {
			excelLog="xxx";//给一个假值，让表头初始化
		}
		$('#dg2').datagrid({
			url: '${ctx}/bill/stream/inaccountstatistics_detail',
			method: 'post',
			iconCls: 'icon-save',
			queryParams:{//每次请求的参数
				uuid: excelLog,
				casemanageId:case_uuId
			},
			pageList:[10,20,40,50,100],//每页记录数选择范围设置
			pageNumber:1,//当前页号,
			pageSize:10,//每页显示记录数
			loadMsg:"正在加载，请稍后",//加载数据时的提示信息
			emptyMsg:"暂无信息",//加载数据为空时的信息
			rownumbers:true,//序号
			fitColumns: true,//使表格自适应页面宽度
			pagination: true,//是否分页
			singleSelect: true,
			columns:[[ //每一列的具体设置。
				{field:'ACCOUNT_BODY',title:'交易主体'},
				{field:'ACCOUNT_BODY_NUMBER',title:'交易主体账号'},
				{field:'ACCOUNT_BODY_CARD',title:'交易主体卡号'},
				{field:'ACCOUNT_RIVAL',title:'交易对手'},
				{field:'ACCOUNT_RIVAL_NUMBER',title:'交易对手账号'},
				{field:'ACCOUNT_RIVAL_CARD',title:'交易对手卡号'},
				{field:'SIGN',title:'交易类型',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						return value==0?'流入':'流出'
					}
				},
				{field:'TRADE_DATE',title:'交易时间',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if(value){
							var date = new Date(value);
							return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
						}else{
							return '-';
						}
					}
				},
				{field:'ACCOUNT_MONEY',title:'交易金额', sortable : true},
				{field:'SURPLUS_MONEY',title:'交易后余额', sortable : true},
				{field:'CONTENT_ABSTRACT',title:'摘要'},
				{field:'ACCOUNT_RIVAL_BANK',title:'对手归属行'},
				{field:'ACCOUNT_BODY_BANK',title:'主体归属行'},
				{field:'INSTITUTION_NUMBER',title:'对方机构号'},
				{field:'TELLER_NUMBER',title:'柜员号'},
				{field:'REMARKS',title:'备注'}
			]],
			onLoadSuccess: function(data){
			}
		});
	};
	function dg2zdy(excelLog){
		if (!case_uuId) {
			toastr.error("案件id为空");
			return;
		}
		if (!excelLog) {
			excelLog="xxx";//给一个假值，让表头初始化
		}
		$('#dg2zdy').datagrid({
			url: '${ctx}/bill/stream/inaccountstatistics_detail',
			method: 'post',
			iconCls: 'icon-save',
			queryParams:{//每次请求的参数
				uuid: excelLog,
				casemanageId:case_uuId
			},
			height:450,
			width:1500,
			pageList:[20,40,50,100],//每页记录数选择范围设置
			pageNumber:1,//当前页号,
			pageSize:20,//每页显示记录数
			loadMsg:"正在加载，请稍后",//加载数据时的提示信息
			emptyMsg:"暂无信息",//加载数据为空时的信息
			//height: 710,
			rownumbers:true,//序号
			fitColumns: true,//使表格自适应页面宽度
			pagination: true,//是否分页
			singleSelect: true,
			columns:[[ //每一列的具体设置。
				{field:'ACCOUNT_BODY',title:'交易主体'},
				{field:'ACCOUNT_BODY_NUMBER',title:'交易主体账号'},
				{field:'ACCOUNT_BODY_CARD',title:'交易主体卡号'},
				{field:'ACCOUNT_RIVAL',title:'交易对手'},
				{field:'ACCOUNT_RIVAL_NUMBER',title:'交易对手账号'},
				{field:'ACCOUNT_RIVAL_CARD',title:'交易对手卡号'},
				{field:'SIGN',title:'交易类型',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						return value==0?'流入':'流出'
					}
				},
				{field:'TRADE_DATE',title:'交易时间',
					formatter: function(value,row,index){ //当前值，当前的row，当前的索引
						if(value){
							var date = new Date(value);
							return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
						}else{
							return '-';
						}
					}
				},
				{field:'ACCOUNT_MONEY',title:'交易金额', sortable : true},
				{field:'SURPLUS_MONEY',title:'交易后余额', sortable : true},
				{field:'CONTENT_ABSTRACT',title:'摘要'},
				{field:'ACCOUNT_RIVAL_BANK',title:'对手归属行'},
				{field:'ACCOUNT_BODY_BANK',title:'主体归属行'},
				{field:'INSTITUTION_NUMBER',title:'对方机构号'},
				{field:'TELLER_NUMBER',title:'柜员号'},
				{field:'REMARKS',title:'备注'}
			]],
			onLoadSuccess: function(data){
			}
		});
	};
	function delLog(dealFlowUuid,tableFlat,importDetailId){
		$.ajax({
			url: "${ctx}/datalog/deleteFlow",
			type: "post",
			data: {
				dealFlowUuid: dealFlowUuid,
				tableFlat:tableFlat,
				importDetailId:importDetailId,
                caseManagerId:case_uuId,
			},
			success: function (msg) {
				toastr.success("删除成功");
				$('#dg').datagrid('reload');
			}
		})
	};
	function initTitlePoll(){
        var d = top.dialog({
            title : "标题管理",
            modal : true,
            url : '${ctx}/bill/titlepool/showTitlePool',
            height : 880,
            width : 1500,
            onclose : function() {
                window.location.reload();
            }

        });
        d.show();
        return false;
	};
	function showCaseObjectMapping(){
		var data = {"fileUUids": fileUUids,"casemanageId": case_uuId}
        var d = top.dialog({
            title : "关联案件对象",
            modal : true,
            url : '${ctx}/casemanage/showCaseObjectBillMapping',
            height : 880,
            width : 1500,
            data : data
        });
        d.show();
        return false;
	};
	let importLog=new Vue({
		el: ".result",
		data: {
			logDataArr: [],
			excelVal: '',
			activeName:'first',
		},
		methods: {
			handleClick(){
				if (this.activeName=='second'&&this.logDataArr.length>0) {
					this.excelVal=this.logDataArr[0].DEAL_FLOW_UUID
				}else{
					this.excelVal=''   //初始化uuid
				}
				this.changeHandle()
			},
			changeHandle(){
				dg2(this.excelVal);
			}
		}
	});
	let importLog2=new Vue({
		el: ".zdyresultend",
		data: {
			logDataArr: [],
			excelVal: '',
			activeName:'first',
		},
		methods: {
			handleClick(){
				if (this.activeName=='second'&&this.logDataArr.length>0) {
					this.excelVal=this.logDataArr[0].DEAL_FLOW_UUID
				}else{
					this.excelVal=''   //初始化uuid
				}
				this.changeHandle()
			},
			changeHandle(){
				dg2zdy(this.excelVal);
			}
		}
	});
	function removeByValue(arr, val) {
		for(var i = 0; i < arr.length; i++) {
			if(arr[i] == val) {
			arr.splice(i, 1);
			break;
			}
		};
	};
	(function (){
        $.extend($.fn.datagrid.methods, {
            //显示遮罩
            loading: function(jq){
                return jq.each(function(){
                    $(this).datagrid("getPager").pagination("loading");
                    var opts = $(this).datagrid("options");
                    var wrap = $.data(this,"datagrid").panel;
                    if(opts.loadMsg)
                    {
                        $("<div class=\"datagrid-mask\"></div>").css({display:"block",width:wrap.width(),height:wrap.height()}).appendTo(wrap);
                        $("<div class=\"datagrid-mask-msg\"></div>").html(opts.loadMsg).appendTo(wrap).css({display:"block",left:(wrap.width()-$("div.datagrid-mask-msg",wrap).outerWidth())/2,top:(wrap.height()-$("div.datagrid-mask-msg",wrap).outerHeight())/2});
                    }
                });
            },
            //隐藏遮罩
            loaded: function(jq){
                return jq.each(function(){
                    $(this).datagrid("getPager").pagination("loaded");
                    var wrap = $.data(this,"datagrid").panel;
                    wrap.find("div.datagrid-mask-msg").remove();
                    wrap.find("div.datagrid-mask").remove();
                });
            }
        });
    })(jQuery);

</script>
<style>
	.el-tabs--border-card{
		-webkit-box-shadow:none!important;
		box-shadow:none!important;
	}
	.panel-body {
		border-color: transparent!important;
	}
	ul.nav.nav-tabs.navzi {
		height: 50px;
	}
	ul.nav.nav-tabs.navzi li{
		height: 50px;
	}
	ul.nav.nav-tabs.navzi li a{
		height: 48px;
	}
	.tabs-container .nav-tabs.navzi > li.active > a{
		border-color: transparent!important;
		color: #000;
	}
	.top-navigation .nav > li a:focus, .top-navigation .nav > li a:hover{
		color: #000;
	}
	.importti {
		height: 27px;
		padding-left: 19px;
		position: relative;
		margin-top: 10px;
	}
	span.importfont {
		margin-left: 14px;
	}
	.file-preview{
		border-color: transparent;
		padding: 0;
	}
	.file-drop-zone{
		margin: 0;
	}
	span.importstar {
		font-size: 18px;
		color: red;
		position: absolute;
		top: 4px;
		margin-right: 14pxx;
	}
	#myModalLabel {
		color:black;
		text-align: left;
	}
	div#addform {
		overflow: hidden;
	}
	.modal-body {
		padding: 10px;
	}
	.el-select-dropdown__item.selected{
		background: #FFFFFF;
	}
	.el-select-dropdown__item.selected.hover{
		background: #f5f7f5 !important;
	}
	.el-select-dropdown__item.selected{
		color: #409EFF;
	}
	.importAndClear{
		width: 200px;
		margin: 0 auto;
		height: 40px
	}
	.importAndClearZdy{
		width: 400px;
		margin: 0 auto;
		height: 40px
	}
	.importAndClear a{
		line-height: 40px;
		padding-left: 10px;
	}
	.result{
		display: none;
	}
	.zdyresultend{
		display: none;
	}
	.zdyresult{
		margin-top: 40px;
		display: none;
	}
	.detail{
		margin-top: 20px;
	}
	.el-tabs--border-card>.el-tabs__header .el-tabs__item{
		margin: 0;
	}
	.el-tabs--border-card{
		border-top: transparent;
	}
	.el-tabs__item.is-active {
		border-top: 1px solid #E4E7ED !important;
	}
	.el-tabs__item.is-active {
		color: #000!important;
	}
	.el-tabs__item.is-active {
		height: 40px;
	}
	.el-tabs__nav {
		height: 40px;
	}
	.el-tabs__nav-scroll {
		height: 40px;
	}
	.el-tabs__nav-wrap {
		height: 40px;
	}
	.el-tabs__header {
		height: 40px;
	}
	.el-tabs--border-card > .el-tabs__header{
		background-color: #fff;
	}
	.el-tabs--border-card > .el-tabs__content{
		padding: 0;
	}
	.tabs-container .panel-body{
		padding: 0;
	}
	.panel.datagrid.panel-htop {
		border: 1px solid #D3D3D3;
		margin-top: 20px;
	}
	.el-tabs--border-card>.el-tabs__header .el-tabs__item:not(.is-disabled):hover {
		color: #000;
	}
	.el-tabs--border-card{
		border: transparent!important;
	}
	.result {
		padding-left: 10px;
		padding-right: 10px;
	}
	input.el-input__inner {
		margin-top: 20px;
		width: 260px;
		height: 30px;
		border: solid 1px #d9d9d9;
	}
	.el-input__icon{
		top: 35px!important;
	}
	.importAndClear {
	    margin: 0 auto;
	    height: 40px;
	}
	button.el-button.el-button--default {
		border: transparent;
		position: absolute;
		right: 55px;
		top: 0px;
		color: #287CDF;
		z-index: 20;
		background: transparent;
	}
	button.el-button.el-button--default:hover{
		background-color: transparent;
	}
	span.gldxwen {
		background:url("${ctx}/imgs/gldxwen.png") no-repeat;
		display: inline-block;
		width: 14px;
		height: 14px;
		vertical-align: middle;
		margin-left: 5px;
	}
	.gldx {
		width: 130px!important;
		height: 30px;
		line-height: 6px;
		margin-right: -3px;
		position: absolute;
		right: 40px;
		z-index: 2;
	}
</style>
